package com.ft.admix.bd.adapter;

import android.app.Activity;
import android.support.annotation.Nullable;

import com.kwad.sdk.api.KsAdSDK;
import com.kwad.sdk.api.KsFeedAd;
import com.kwad.sdk.api.KsLoadManager;
import com.kwad.sdk.api.KsScene;
import com.ft.admix.ad.MixCustomNativeAdapter;
import com.ft.admix.config.AdConfig;

import java.util.ArrayList;
import java.util.List;

public class NativeAdapterLoader extends MixCustomNativeAdapter {

    @Override
    public void load(Activity context, AdConfig config) {
        if (!KsAdSDK.haseInit()||KsAdSDK.getLoadManager() == null) {
            callLoadFailed(-1, "快手SDK未初始化");
            return;
        }
        KsScene ksScene = new KsScene.Builder(Long.parseLong(config.getAdId()))
                .build();

        KsAdSDK.getLoadManager().loadConfigFeedAd(ksScene, new KsLoadManager.FeedAdListener() {
            @Override
            public void onError(int i, String s) {
                callLoadFailed(i, s);
            }

            @Override
            public void onFeedAdLoad(@Nullable @androidx.annotation.Nullable List<KsFeedAd> list) {
                if (list == null || list.isEmpty()) {
                    callLoadFailed(999, "无广告数据");
                    return;
                }

                List<CustomKsFeedAd> nativeAds = new ArrayList<>();
                for (KsFeedAd ksFeedAd : list) {
                    nativeAds.add(new CustomKsFeedAd(context, ksFeedAd));
                }
                callLoadSuccess(nativeAds);
            }
        });

    }

    @Override
    public void destroy() {
        // 清理资源
    }
} 